package src.com.foreknow.demo11;

/**
 * 方法的参数和返回值类型可以为父类型
 */
public class Test {
    public void m1(Pet pet){
        System.out.println(pet.getHealth());
    }

    public Pet m2(){
        Dog d = new Dog();
        d.setHealth(50);
        return d;
    }

    public static void main(String[] args) {
        Test test = new Test();
        Penguin p = new Penguin();
        p.setHealth(10);
        test.m1(p);
        Pet pet = test.m2();
        System.out.println(pet.getHealth());
    }
}













